package com.pinyougou.manager.controller;

import com.alibaba.dubbo.config.annotation.Reference;
import com.pinyougou.common.PageResult;
import com.pinyougou.pojo.Goods;
import com.pinyougou.service.GoodsService;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/goods")
public class GoodsController
{
    @Reference(timeout=10000)
    private GoodsService goodsService;

    @GetMapping("/findByPage")
    public PageResult findByPage(Goods goods, Integer page, @RequestParam(defaultValue = "10") Integer rows)
    {
        /*String loginName = SecurityUtils.getSubject().getPrincipal().toString();
        goods.setSellerId(loginName);*/
        return goodsService.findByPage(goods,page,rows);
    }

    @GetMapping("/updateStatus")
    public boolean updateAuditStatus(Long[] ids, String auditStatus)
    {
        try
        {
            if (StringUtils.isEmpty(auditStatus))
            {
                goodsService.updateStatus("is_delete",ids,"1");
                return true;
            }
            goodsService.updateStatus("audit_status",ids,auditStatus);
            return true;
        }
        catch (Exception e)
        {
            e.printStackTrace();
        }
        return false;
    }
}